package com.o2o.cleaning.month.platform.ebusiness_plat.yangmatou

import com.o2o.utils.Iargs
import org.apache.spark.sql.{DataFrame, SparkSession}

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2020/6/5 16:23
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object CheckTaobaoObsData {
  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .appName(s"${this.getClass.getSimpleName}")
      .config("spark.debug.maxToStringFields", "2000")
      .config("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .config("spark.sql.caseSensitive", "true")
//      .config("es.nodes", "192.168.1.29")
//      .config("es.port", "9200")
//      .config("cluster.name","O2OElastic")
//      .config("es.net.http.auth.user", "elastic")
//      .config("es.net.http.auth.pass", "changeme")
//      .master("local[*]")
      .getOrCreate()

    val sc = spark.sparkContext
    sc.hadoopConfiguration.set("fs.s3a.access.key", Iargs.OBSACCESS)
    sc.hadoopConfiguration.set("fs.s3a.secret.key", Iargs.OBSSECRET)
    sc.hadoopConfiguration.set("fs.s3a.endpoint", Iargs.OBSENDPOINT)
    sc.setLogLevel("WARN")
    var year ="2020"
    var month = "7"
    var platform = "dzdp"

    val goodpath= "s3a://o2o-dataproces-group/panzonghao/taobao/2020/7/zhibo_finally/"
    val lastgoodpath= "s3a://dws-data/g_data/2020/6/taobao/"

    val frame: DataFrame = spark.read.orc(goodpath)
    val frame1: DataFrame = spark.read.orc(lastgoodpath)

//    frame.printSchema()
//    frame1.printSchema()


    frame.registerTempTable("taobao")
    frame1.registerTempTable("lasttaobao")
    frame.cache()
    frame1.cache()

    println("==============2020-07============直播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |taobao
        |where is_showLive = 'true'
      """.stripMargin).show()
    println("==============2020-06============直播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |lasttaobao
        |where is_showLive = 'true'
      """.stripMargin).show()
    println("==============2020-07============店铺主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |taobao
        |where is_showLive = 'true' and is_selfLive = 'true'
      """.stripMargin).show()
    println("==============2020-06============店铺主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |lasttaobao
        |where is_showLive = 'true' and is_selfLive = 'true'
      """.stripMargin).show()
    println("==============2020-07============达人主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |taobao
        |where is_showLive = 'true' and is_selfLive = 'false'
      """.stripMargin).show()
    println("==============2020-06============达人主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |lasttaobao
        |where is_showLive = 'true' and is_selfLive = 'false'
      """.stripMargin).show()
    println("==============2020-07============aliv主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |taobao
        |where is_showLive = 'true' and is_aliv = true
      """.stripMargin).show()
    println("==============2020-06============aliv主播总数")
    spark.sql(
      """
        |select
        |sum(cast(viewcount as bigint)),
        |sum(cast(liveCount as bigint)),
        |sum(cast(liveAvg_priceText as double))
        |from
        |lasttaobao
        |where is_showLive = 'true' and is_aliv = true
      """.stripMargin).show()
    sc.stop()
}
}
